home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 4.3 KB | 195 lines | [TEXT/ToyS] |
- -- Preferences
- property kasPrefName : "NetScape to WebStar SSI"
-
- property kasWebStarSSI : "<!--#include virtual="
- property kasNetScapeSSI : "<!--#include file="
-
- property kasTypesToDo : {"TEXT"} -- Only run on these types
- property kasExtToDo : "" -- Use non-empty match string (e.g. "*.html") to limit to that extension
-
- -- Globals
- global gasInfoWind -- Info window
- global gasInfoPos -- Position of info window
- global gasFoldersToDo -- The folders left to process
- global gasConverted -- Number gone!
- global gasChecked -- Number checked!
- global gasPrefix -- Adjusted kasPrefix (munge the % parms)
-
-
- on open fsObjs
- -- Load prefs, show window
- pfLoad()
-
- set gasConverted to 0
- set gasChecked to 0
-
- set gasInfoWind to display info titled kasPrefName ¬
- located at gasInfoPos ¬
- message "Scanning…"
-
- -- Do files
- set gasFoldersToDo to {}
-
- repeat with fsObj in fsObjs
- set myInfo to (basic info for fsObj)
-
- if (system type of myInfo is "fold") then
- set gasFoldersToDo to gasFoldersToDo & {fsObj}
- else if (system type of myInfo is in kasTypesToDo) then
- if (kasExtToDo is "") or ((collect lines of (catalog name of myInfo) that match kasExtToDo) is not "") then
- DoOne(fsObj)
- end if
- end if
- end repeat
-
- -- Do folders
- repeat while gasFoldersToDo is not {}
- -- Pop one off the end
- set n to the number of items of gasFoldersToDo
- set fsObj to item n of gasFoldersToDo
-
- if (n > 1) then
- set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
- else
- set gasFoldersToDo to {}
- end if
-
- display info gasInfoWind ¬
- message ("Folders to go: " & n) ¬
- at line 6 ¬
- using color (15 * 32)
-
- -- Process it
- GoDeep(fsObj)
- end repeat
-
- display info gasInfoWind message "DONE!"
-
- pause for 5 with seconds timing -- Let screen wait...
-
- set gasInfoPos to screen location of ¬
- (display info gasInfoWind with disposal)
-
- pfSave() -- Save window location
- end open
-
-
- on DoOne(fsObj)
- set aFileInfo to (alias info from fsObj)
-
- display info gasInfoWind ¬
- message "File: " & (original name of aFileInfo) ¬
- at line 2
-
- set gasChecked to gasChecked + 1
-
- display info gasInfoWind ¬
- message ("Checked: " & gasChecked) ¬
- at line 7 ¬
- using color 15
-
- ConvertFile(fsObj)
- end DoOne
-
-
- on ConvertFile(fsObj)
- try
- set fileRef to ¬
- open fork from fsObj ¬
- with write access
- on error errStr
- display info gasInfoWind ¬
- message ("Error: " & errStr) ¬
- at line 12 ¬
- using color (25 * 1024)
- return
- end try
-
- set fname to catalog name of (basic info for fsObj)
-
- set fileData to read data from fileRef
- set newData to fileData
-
- -- Convert SSI!
- set newData to munge newData ¬
- searching for kasWebStarSSI ¬
- replacing it with kasNetScapeSSI
-
- -- Rename to lowercase?
- if (not (the same data is in fileData given «class Cmp≈»:newData)) then
- -- Reset file to 0 long
- size fork fileRef given «class len »:0
- -- Write data
- write data to fileRef from buffer newData
-
- set gasConverted to gasConverted + 1
-
- display info gasInfoWind ¬
- message ("Converted: " & gasConverted) ¬
- at line 8 ¬
- using color (15 * 1024)
- display info gasInfoWind ¬
- message ("Last: " & fname) ¬
- at line 9 ¬
- using color (16 * 1024)
- end if
-
- close fork fileRef
- end ConvertFile
-
-
-
- on GoDeep(foldObj)
- display info gasInfoWind ¬
- message "Path: " & (foldObj as string)
-
- set daddy to foldObj as string
-
- -- Do kinds that match
- display info gasInfoWind ¬
- message "Scanning files" at line 5
-
- if (kasExtToDo is "") then
- set myItems to the entries in foldObj ¬
- whose types are in kasTypesToDo
- else
- set myItems to the entries in foldObj ¬
- whose types are in kasTypesToDo ¬
- whose names match kasExtToDo
- end if
-
- repeat with myItem in myItems
- DoOne((daddy & myItem) as alias)
- end repeat
-
- -- Do folders
- display info gasInfoWind ¬
- message "Scanning subfolders" at line 5
-
- set myItems to the entries in foldObj ¬
- whose kinds are a folder
-
- repeat with myItem in myItems
- set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
- end repeat
-
- -- Done
- display info gasInfoWind ¬
- message "…" at line 5
- end GoDeep
-
-
- on pfLoad()
- try
- set ourPrefs to (load preference named kasPrefName)
- set gasInfoPos to item 1 of ourPrefs
- on error
- set gasInfoPos to {0, 0}
- end try
- end pfLoad
-
-
- on pfSave()
- save preference {gasInfoPos} named kasPrefName
- end pfSave
-